﻿////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// <copyright>Copyright 2008-2011 Andreas Huber Doenni</copyright>
// Distributed under the Microsoft Public License (Ms-PL).
// See accompanying file License.txt or copy at http://mews.codeplex.com/license.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

namespace Mews.Mime
{
    using System;

    /// <summary>Implements the common functionality for all <see cref="Body"/> subclasses.</summary>
    /// <typeparam name="TMostDerived">The most-derived subclass of this type.</typeparam>
    /// <threadsafety static="true" instance="false"/>
    public abstract class Body<TMostDerived> : Body, IVisitable<TMostDerived, Body>
        where TMostDerived : Body<TMostDerived>
    {
        /// <summary>See <see cref="IVisitable{T}.Accept"/>.</summary>
        public sealed override void Accept(IVisitor<Body> visitor)
        {
            VisitableHelper.Accept(this, visitor);
        }

        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        internal Body(string subtype, FallbackReason fallbackReason) : base(subtype, fallbackReason)
        {
        }

        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>Initializes a new instance of the <see cref="Body{TMostDerived}"/> class.</summary>
        /// <param name="subtype">The subtype of the body, usually all-lowercase.</param>
        /// <exception cref="ArgumentException"><paramref name="subtype"/> is <c>null</c> or empty.</exception>
        protected Body(string subtype) : this(subtype, null)
        {
            if (string.IsNullOrEmpty(subtype))
            {
                throw new ArgumentException("Cannot be null or empty.", "subtype");
            }
        }
    }
}
